/*     */ package com.umeng.analytics.a;
/*     */ 
/*     */ import android.content.Context;
/*     */ import android.content.SharedPreferences;
/*     */ import android.content.SharedPreferences.Editor;
/*     */ import android.text.TextUtils;
/*     */ import com.umeng.analytics.f;
/*     */ import com.umeng.analytics.j;
/*     */ import com.umeng.common.Log;
/*     */ import com.umeng.common.b;
/*     */ import java.util.ArrayList;
/*     */ import java.util.Date;
/*     */ import org.json.JSONArray;
/*     */ import org.json.JSONObject;
/*     */ 
/*     */ public class m extends l
/*     */   implements g
/*     */ {
/*     */   public o a;
/*     */   public p b;
/*  31 */   public long c = 0L;
/*     */ 
/*  33 */   private ArrayList<k> d = new ArrayList();
/*     */   private static final String k = "duration";
/*     */   private static final String l = "activities";
/*     */   private static final String m = "terminate_time";
/*     */ 
/*     */   public m()
/*     */   {
/*     */   }
/*     */ 
/*     */   public m(String paramString)
/*     */   {
/*  43 */     this.e = paramString;
/*     */   }
/*     */ 
/*     */   public static m a(Context paramContext) {
/*  47 */     SharedPreferences localSharedPreferences = j.e(paramContext);
/*     */ 
/*  49 */     String str = localSharedPreferences.getString("session_id", null);
/*     */ 
/*  51 */     if (str == null) return null;
/*     */ 
/*  53 */     m localm = new m(str);
/*     */ 
/*  55 */     o localo = o.b(paramContext);
/*  56 */     if ((localo != null) && (localo.a())) {
/*  57 */       localm.a = localo;
/*     */     }
/*     */ 
/*  60 */     p localp = p.a(paramContext);
/*  61 */     if ((localp != null) && (localp.a())) {
/*  62 */       localm.b = localp;
/*     */     }
/*     */ 
/*  65 */     localm.d = c(localSharedPreferences);
/*  66 */     localm.c = d(localSharedPreferences);
/*     */ 
/*  68 */     String[] arrayOfString = b(localSharedPreferences);
/*     */ 
/*  70 */     if ((arrayOfString != null) && (arrayOfString.length == 2)) {
/*  71 */       localm.g = arrayOfString[0];
/*  72 */       localm.h = arrayOfString[1];
/*     */     }
/*     */ 
/*  75 */     a(localSharedPreferences);
/*     */ 
/*  77 */     return localm;
/*     */   }
/*     */ 
/*     */   private static void a(SharedPreferences paramSharedPreferences) {
/*  81 */     SharedPreferences.Editor localEditor = paramSharedPreferences.edit();
/*     */ 
/*  83 */     localEditor.putLong("duration", 0L);
/*  84 */     localEditor.putString("activities", "");
/*     */ 
/*  86 */     localEditor.commit();
/*     */   }
/*     */ 
/*     */   private static String[] b(SharedPreferences paramSharedPreferences)
/*     */   {
/*  96 */     long l1 = paramSharedPreferences.getLong("terminate_time", 0L);
/*     */ 
/*  98 */     if (l1 <= 0L)
/*     */     {
/* 100 */       return null;
/*     */     }
/*     */ 
/* 103 */     return b.a(new Date(l1)).split(" ");
/*     */   }
/*     */ 
/*     */   private static ArrayList<k> c(SharedPreferences paramSharedPreferences)
/*     */   {
/* 108 */     String str1 = paramSharedPreferences.getString("activities", "");
/*     */ 
/* 110 */     if (!"".equals(str1)) {
/* 111 */       ArrayList localArrayList = new ArrayList();
/*     */       try {
/* 113 */         String[] arrayOfString = str1.split(";");
/* 114 */         for (int i = 0; i < arrayOfString.length; i++) {
/* 115 */           String str2 = arrayOfString[i];
/*     */ 
/* 117 */           localArrayList.add(new k(new JSONArray(str2)));
/*     */         }
/*     */       } catch (Exception localException) {
/* 120 */         localException.printStackTrace();
/*     */       }
/*     */ 
/* 123 */       if (localArrayList.size() > 0) return localArrayList;
/*     */     }
/* 125 */     return null;
/*     */   }
/*     */ 
/*     */   private static long d(SharedPreferences paramSharedPreferences) {
/* 129 */     return paramSharedPreferences.getLong("duration", 0L) / 1000L;
/*     */   }
/*     */ 
/*     */   public static SharedPreferences.Editor a(SharedPreferences paramSharedPreferences, String paramString, long paramLong1, long paramLong2)
/*     */   {
/* 134 */     long l1 = paramLong2 - paramLong1;
/* 135 */     long l2 = paramSharedPreferences.getLong("duration", 0L);
/*     */ 
/* 137 */     SharedPreferences.Editor localEditor = paramSharedPreferences.edit();
/*     */ 
/* 139 */     if (com.umeng.analytics.g.j) {
/* 140 */       String str1 = paramSharedPreferences.getString("activities", "");
/* 141 */       String str2 = paramString;
/* 142 */       if (!"".equals(str1)) {
/* 143 */         str1 = str1 + ";";
/*     */       }
/* 145 */       str1 = str1 + String.format("[\"%s\",%d]", new Object[] { str2, Long.valueOf(l1 / 1000L) });
/* 146 */       localEditor.remove("activities");
/* 147 */       localEditor.putString("activities", str1);
/*     */     }
/*     */ 
/* 150 */     localEditor.putLong("duration", l2 + l1);
/* 151 */     localEditor.putLong("terminate_time", paramLong2);
/* 152 */     localEditor.commit();
/*     */ 
/* 154 */     return localEditor;
/*     */   }
/*     */ 
/*     */   public static SharedPreferences.Editor a(SharedPreferences paramSharedPreferences, ArrayList<f> paramArrayList, long paramLong1, long paramLong2) {
/* 158 */     long l1 = paramLong2 - paramLong1;
/* 159 */     long l2 = paramSharedPreferences.getLong("duration", 0L);
/*     */ 
/* 161 */     SharedPreferences.Editor localEditor = paramSharedPreferences.edit();
/*     */ 
/* 163 */     if (paramArrayList.size() > 0) {
/* 164 */       String str = paramSharedPreferences.getString("activities", "");
/* 165 */       StringBuilder localStringBuilder = new StringBuilder();
/*     */ 
/* 167 */       if (!TextUtils.isEmpty(str)) {
/* 168 */         localStringBuilder.append(str);
/* 169 */         localStringBuilder.append(";");
/*     */       }
/*     */ 
/* 172 */       for (f localf : paramArrayList) {
/* 173 */         localStringBuilder.append(String.format("[\"%s\",%d]", new Object[] { localf.a, Long.valueOf(localf.b / 1000L) }));
/* 174 */         localStringBuilder.append(";");
/*     */       }
/*     */ 
/* 177 */       localStringBuilder.deleteCharAt(localStringBuilder.length() - 1);
/*     */ 
/* 179 */       localEditor.remove("activities");
/* 180 */       localEditor.putString("activities", localStringBuilder.toString());
/*     */     }
/*     */ 
/* 183 */     localEditor.putLong("duration", l2 + l1);
/* 184 */     localEditor.putLong("terminate_time", paramLong2);
/* 185 */     localEditor.commit();
/*     */ 
/* 187 */     return localEditor;
/*     */   }
/*     */ 
/*     */   public boolean a() {
/* 191 */     if ((this.a == null) && (com.umeng.analytics.g.i)) {
/* 192 */       Log.c("MobclickAgent", "missing location info in Terminate");
/*     */     }
/*     */ 
/* 195 */     if (this.b == null) {
/* 196 */       Log.e("MobclickAgent", "missing receive and transport Traffic in Terminate ");
/*     */     }
/*     */ 
/* 199 */     if (this.c <= 0L) {
/* 200 */       Log.b("MobclickAgent", "missing Duration info in Terminate");
/*     */ 
/* 202 */       return false;
/*     */     }
/*     */ 
/* 205 */     if ((this.d == null) || (this.d.size() == 0)) {
/* 206 */       Log.e("MobclickAgent", "missing Activities info in Terminate");
/*     */     }
/*     */ 
/* 209 */     return super.a();
/*     */   }
/*     */ 
/*     */   private void c(JSONObject paramJSONObject) throws Exception {
/* 213 */     if (this.b != null) this.b.b(paramJSONObject); 
/*     */   }
/*     */ 
/*     */   private void d(JSONObject paramJSONObject) throws Exception {
/* 217 */     if (this.a != null) this.a.b(paramJSONObject); 
/*     */   }
/*     */ 
/*     */   private void e(JSONObject paramJSONObject) throws Exception {
/* 221 */     o localo = new o();
/* 222 */     localo.a(paramJSONObject);
/* 223 */     if (localo.a())
/* 224 */       this.a = localo;
/*     */   }
/*     */ 
/*     */   private void f(JSONObject paramJSONObject) throws Exception
/*     */   {
/* 229 */     p localp = new p();
/* 230 */     localp.a(paramJSONObject);
/* 231 */     if (localp.a())
/* 232 */       this.b = localp;
/*     */   }
/*     */ 
/*     */   private void g(JSONObject paramJSONObject) throws Exception
/*     */   {
/* 237 */     if (paramJSONObject.has("activities")) {
/* 238 */       JSONArray localJSONArray = paramJSONObject.getJSONArray("activities");
/* 239 */       k localk = null;
/*     */ 
/* 241 */       for (int i = 0; i < localJSONArray.length(); i++)
/*     */       {
/* 243 */         localk = new k(localJSONArray.getJSONArray(i));
/*     */ 
/* 245 */         this.d.add(localk);
/*     */       }
/*     */     }
/*     */   }
/*     */ 
/*     */   private void h(JSONObject paramJSONObject) throws Exception {
/* 251 */     if (this.d.size() == 0) {
/* 252 */       return;
/*     */     }
/* 254 */     JSONArray localJSONArray1 = new JSONArray();
/* 255 */     JSONArray localJSONArray2 = null;
/* 256 */     for (k localk : this.d)
/*     */     {
/* 258 */       localJSONArray2 = new JSONArray();
/* 259 */       localJSONArray2.put(localk.a);
/* 260 */       localJSONArray2.put(localk.b);
/*     */ 
/* 262 */       localJSONArray1.put(localJSONArray2);
/*     */     }
/*     */ 
/* 265 */     paramJSONObject.put("activities", localJSONArray1);
/*     */   }
/*     */ 
/*     */   public void a(JSONObject paramJSONObject)
/*     */   {
/*     */     try
/*     */     {
/* 273 */       super.a(paramJSONObject);
/*     */ 
/* 275 */       this.c = paramJSONObject.getLong("duration");
/*     */ 
/* 277 */       f(paramJSONObject);
/* 278 */       e(paramJSONObject);
/* 279 */       g(paramJSONObject);
/*     */     } catch (Exception localException) {
/* 281 */       localException.printStackTrace();
/*     */     }
/*     */   }
/*     */ 
/*     */   public void b(JSONObject paramJSONObject)
/*     */     throws Exception
/*     */   {
/* 288 */     super.b(paramJSONObject);
/*     */ 
/* 290 */     if (this.c > 0L) {
/* 291 */       paramJSONObject.put("duration", this.c);
/*     */     }
/*     */ 
/* 294 */     c(paramJSONObject);
/* 295 */     d(paramJSONObject);
/* 296 */     h(paramJSONObject);
/*     */   }
/*     */ }

/* Location:           C:\Users\Administrator\Desktop\umeng_sdk.jar
 * Qualified Name:     com.umeng.analytics.a.m
 * JD-Core Version:    0.6.2
 */